<?php

namespace App\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Contracts\Routing\Registrar as Router;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @return void
     */
    public function boot()
    {
        //

        parent::boot();
    }

    /**
     * Define the routes for the application.
     *
     * @return void
     */
    public function map(Router $router)
    {
        // $router->group(['namespace' => $this->namespace], function ($router) {               
        //    // // require app_path('route/HomeRoutes.php');
        //     // foreach (glob(app_path('Http//Routes') . '/*.php') as $file) {
        //     //     $this->app->make('App\\Http\\Routes\\' . basename($file, '.php'))->map($router);
        //     // }

        // });

        $this->mapApiRoutes();

        $this->mapWebRoutes();


        $this->mapAdminRoutes();
        $this->mapSHomeRoutes();
        $this->mapSAdminRoutes();
        
    }

    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes()
    {
        Route::middleware('web')
             ->namespace($this->namespace)
             ->group(base_path('routes/web.php'));
    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::prefix('api')
             ->middleware('api')
             ->namespace($this->namespace)
             ->group(base_path('routes/api.php'));
    }

    protected function mapAdminRoutes()
    {
        Route::prefix('admin')         
        // ->middleware('admin')        
         ->namespace($this->namespace.'\Admin')        
          ->group(base_path('routes/admin.php'));
    }


    protected function mapSHomeRoutes()
    {
         Route::prefix('sHome')         
        // ->middleware('sHome')        
         ->namespace($this->namespace.'\SHome')        
          ->group(base_path('routes/sHome.php'));
    }
    protected function mapSAdminRoutes()
    {
        Route::prefix('sAdmin')         
        // ->middleware('sHome')        
         ->namespace($this->namespace.'\SAdmin')        
          ->group(base_path('routes/sAdmin.php'));
    }
}
